<% metadata_for_verification = SmartContract.get_address_verified_bytecode_twin_contract(@address_hash) %>
<% changeset = (if assigns[:retrying], do: @changeset, else: SmartContract.merge_twin_contract_with_changeset(metadata_for_verification, @changeset)) |> SmartContract.address_to_checksum_address() %>
<% fetch_constructor_arguments_automatically = if metadata_for_verification, do: true, else: changeset.changes[:autodetect_constructor_args] || true %>
<% display_constructor_arguments_text_area = if fetch_constructor_arguments_automatically, do: "none", else: "block" %>
<section data-page="contract-verification" class="container new-smart-contract-container">
  <%= render BlockScoutWeb.CommonComponentsView, "_channel_disconnected_message.html", text: gettext("Connection Lost") %>

  <div class="new-smart-contract-form">
      <h1 class="smart-contract-title"><%= gettext "New Smart Contract Verification via Standard input JSON" %></h1>
      <%= form_for changeset,
                address_contract_verification_path(@conn, :create),
                [id: "standard-json-dropzone-form"],
                fn f -> %>
      <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_contract_address_field.html", f: f %>

      <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_contract_name_field.html", f: f, tooltip: "Must match the name specified in the code. For example, in <span class=\"tooltip-quote\">contract MyContract {..}</span> <strong>MyContract</strong> is the contract name. Also contract name could be: <span class=\"tooltip-quote\"><strong>path/to/file.sol:MyContract</strong></span>" %>

      <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_include_nightly_builds_field.html", f: f %>

      <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_compiler_field.html", f: f, compiler_versions: @compiler_versions, tooltip: "The compiler version is specified in <span class=\"tooltip-quote\">pragma solidity X.X.X</span>. Use the compiler version rather than the nightly build. If using the Solidity compiler, run <span class=\"tooltip-quote\">solc —version</span> to check." %>

      <div class="smart-contract-form-group">
        <div class="smart-contract-form-group-inner-wrapper">
        <label for="smart_contract_metadata_json"><%= gettext("Standard Input JSON") %></label>
          <div class="center-column">
            <div class="dropzone-1 dropzone-previews" style="display: flex; margin: 0 auto;", id="dropzone-previews">
              <div style="text-align: center;">
                <span class="dz-message btn-full-primary" id="dz-button-message"><%= gettext("Drop the standard input JSON file or click here") %></span>
                <%= error_tag f, :files, id: "file-help-block", class: "text-danger form-error", style: "max-width: 600px;" %>
              </div>
            </div>
          </div>
          <div class="smart-contract-form-group-tooltip">Drop the standard input JSON file created during contract compilation into the drop zone.</div>
        </div>
      </div>

      <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_fetch_constructor_args.html", f: f %>

      <%= render BlockScoutWeb.AddressContractVerificationCommonFieldsView, "_constructor_args.html", f: f, display_constructor_arguments_text_area: display_constructor_arguments_text_area %>

      <div class="smart-contract-form-buttons">
        <button
          class="position-absolute w-118 btn-full-primary d-none mr-2"
          disabled="true"
          id="loading"
          name="button"
          type="button"
        >
          <%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html", loading_text: gettext("Loading...") %>
        </button>
        <button id="verify-via-standard-json-input-submit" class="btn-full-primary mr-2" disabled data-button-loading="animation"><%= gettext("Verify & publish") %></button>
        <%= reset gettext("Reset"), class: "btn-line mr-2 js-smart-contract-form-reset" %>
        <%=
          link(
            gettext("Cancel"),
            class: "btn-no-border",
            to: address_contract_path(@conn, :index, @address_hash)
            )
        %>
      </div>
      <% end %>
    </div>
</section>
<script defer data-cfasync="false" src="<%= static_path(@conn, "/js/app.js") %>"></script>
